home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Components / Microsoft ASP / _SETUP.1 / ASPWizard.jar / asp / netobjects / nfx / wizard / Wizard.class (.txt) next >
Encoding:
Java Class File  |  1998-11-20  |  5.9 KB  |  187 lines

  1. package asp.netobjects.nfx.wizard;
  2.  
  3. import asp.netobjects.nfx.util.ExceptionHandler;
  4. import asp.netobjects.nfx.util.ExternalError;
  5. import asp.netobjects.nfx.util.InternalError;
  6. import com.sun.java.swing.JFrame;
  7. import java.awt.Frame;
  8. import java.util.Enumeration;
  9. import java.util.Hashtable;
  10. import java.util.Observable;
  11. import java.util.Observer;
  12.  
  13. public class Wizard extends Observable implements Observer {
  14.    private WizardView dmWizardView;
  15.    private ExceptionHandler dmExceptionHandler;
  16.    private Hashtable dmPageIndex;
  17.    private String dmCodeBase;
  18.    private WizardPage dmCurrPage;
  19.    private boolean dmOk = true;
  20.  
  21.    public Wizard(Frame parent, String title, String codeBase, ExceptionHandler handler) {
  22.       this.dmExceptionHandler = handler;
  23.       this.dmCodeBase = codeBase;
  24.       this.dmPageIndex = new Hashtable();
  25.       this.dmWizardView = new WizardView(this, parent, title);
  26.    }
  27.  
  28.    public Wizard(JFrame parent, String title, String codeBase, int width, int height, ExceptionHandler handler) {
  29.       this.dmExceptionHandler = handler;
  30.       this.dmCodeBase = codeBase;
  31.       this.dmPageIndex = new Hashtable();
  32.       this.dmWizardView = new WizardView(this, parent, title, width, height);
  33.    }
  34.  
  35.    public ExceptionHandler getExceptionHandler() {
  36.       return this.dmExceptionHandler;
  37.    }
  38.  
  39.    public void setExceptionHandler(ExceptionHandler handler) {
  40.       this.dmExceptionHandler = handler;
  41.    }
  42.  
  43.    public String getCodeBase() {
  44.       return this.dmCodeBase;
  45.    }
  46.  
  47.    public Hashtable getPageIndex() {
  48.       return this.dmPageIndex;
  49.    }
  50.  
  51.    public WizardView getView() {
  52.       return this.dmWizardView;
  53.    }
  54.  
  55.    public WizardPage getCurrPage() {
  56.       return this.dmCurrPage;
  57.    }
  58.  
  59.    public void setVisible(boolean set) {
  60.       this.dmWizardView.setVisible(set);
  61.    }
  62.  
  63.    public boolean isOk() {
  64.       return this.dmOk;
  65.    }
  66.  
  67.    public void setOk(boolean set) {
  68.       this.dmOk = set;
  69.    }
  70.  
  71.    public void initialize() throws InternalError, ExternalError {
  72.       this.dmWizardView.initialize();
  73.       WizardPage firstPage = (WizardPage)this.getPageIndex().get(Integer.toString(1));
  74.       this.dmCurrPage = firstPage;
  75.    }
  76.  
  77.    public void destroy() {
  78.       ((Observable)this).deleteObservers();
  79.       Enumeration e = this.dmPageIndex.elements();
  80.  
  81.       while(e.hasMoreElements()) {
  82.          WizardPage p = (WizardPage)e.nextElement();
  83.          ((Observable)p).deleteObservers();
  84.          this.dmWizardView.removePageView(p.getView());
  85.          p.destroy();
  86.       }
  87.  
  88.       this.dmPageIndex.clear();
  89.    }
  90.  
  91.    public void finish() throws InternalError, ExternalError {
  92.    }
  93.  
  94.    public final void nextPage() throws InternalError, ExternalError {
  95.       this.dmCurrPage.validate();
  96.       this.dmCurrPage.commit();
  97.       this.dmCurrPage = this.getNext(this.dmCurrPage);
  98.       if (this.dmCurrPage.getView() == null) {
  99.          this.dmCurrPage.createView();
  100.          this.add(this.dmCurrPage);
  101.          this.dmWizardView.addPageView(String.valueOf(this.dmCurrPage.getId()), this.dmCurrPage.getView());
  102.       }
  103.  
  104.       this.dmCurrPage.initialize(1);
  105.       this.dmWizardView.showPageView(String.valueOf(this.dmCurrPage.getId()));
  106.       this.enableButtons();
  107.    }
  108.  
  109.    public final void previousPage() throws InternalError, ExternalError {
  110.       this.dmCurrPage = this.getPrevious(this.dmCurrPage);
  111.       if (this.dmCurrPage.getView() == null) {
  112.          this.dmCurrPage.createView();
  113.          this.add(this.dmCurrPage);
  114.          this.dmWizardView.addPageView(String.valueOf(this.dmCurrPage.getId()), this.dmCurrPage.getView());
  115.       }
  116.  
  117.       this.dmCurrPage.initialize(2);
  118.       this.dmWizardView.showPageView(String.valueOf(this.dmCurrPage.getId()));
  119.       this.enableButtons();
  120.    }
  121.  
  122.    public WizardPage getNext(WizardPage page) throws InternalError, ExternalError {
  123.       return page.getNext();
  124.    }
  125.  
  126.    public WizardPage getPrevious(WizardPage page) throws InternalError, ExternalError {
  127.       return page.getPrevious();
  128.    }
  129.  
  130.    public WizardPage getFinal(WizardPage page) throws InternalError, ExternalError {
  131.       return page.getFinal();
  132.    }
  133.  
  134.    public void add(WizardPage page) throws InternalError {
  135.       page.setId(this.dmPageIndex.size() + 1);
  136.       ((Observable)page).addObserver(this);
  137.       Enumeration e = this.dmPageIndex.elements();
  138.  
  139.       while(e.hasMoreElements()) {
  140.          WizardPage p = (WizardPage)e.nextElement();
  141.          ((Observable)p).addObserver(page);
  142.          ((Observable)page).addObserver(p);
  143.       }
  144.  
  145.       this.dmPageIndex.put(String.valueOf(page.getId()), page);
  146.       if (this.dmPageIndex.size() == 1) {
  147.          this.dmCurrPage = page;
  148.          this.dmCurrPage.createView();
  149.          this.dmWizardView.addPageView(String.valueOf(this.dmCurrPage.getId()), this.dmCurrPage.getView());
  150.       }
  151.  
  152.    }
  153.  
  154.    public void enableButtons() {
  155.       boolean prev = false;
  156.       boolean valid = false;
  157.  
  158.       try {
  159.          prev = this.dmCurrPage.getPrevious() != null;
  160.          valid = this.dmCurrPage.isValid();
  161.       } catch (Throwable var3) {
  162.       }
  163.  
  164.       if (prev) {
  165.          this.dmWizardView.enablePrevious(true);
  166.       } else {
  167.          this.dmWizardView.enablePrevious(false);
  168.       }
  169.  
  170.       if (valid && !this.dmCurrPage.isLastPage()) {
  171.          this.dmWizardView.enableNext(true);
  172.       } else {
  173.          this.dmWizardView.enableNext(false);
  174.       }
  175.  
  176.       if (!valid || !this.dmCurrPage.isLastPage() && !this.dmCurrPage.canFinish()) {
  177.          this.dmWizardView.enableFinish(false);
  178.       } else {
  179.          this.dmWizardView.enableFinish(true);
  180.       }
  181.  
  182.    }
  183.  
  184.    public void update(Observable observable, Object object) {
  185.    }
  186. }
  187.